﻿@model Web.Models.MatMenuModel

@{
    ViewBag.Title = "新增菜单";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row">
    <div class="col-lg-12 col-md-12">
        @using (Html.BeginForm("Create", "Home", FormMethod.Post, new { id = "create-form", @class = "form-horizontal", role = "form" })) {
            @Html.Partial("_Notifications")
            <div class="panel">
                <div class="panel-heading">
                    <span><i class="fa fa-plus-square-o fa-fw"></i>@ViewBag.Title</span>
                </div>
                <div class="panel-body">
                    @Html.Partial("_CreateOrEdit", Model)
                </div>
                <div class="panel-footer">
                    <div class="form-group form-actions">
                        <div class="col-lg-offset-2 col-lg-6 col-sm-6">
                            <a class="btn btn-default  " href="~/Home/Index"><i class="fa fa-reply fa-fw"></i>返 回</a>
                            <button class="btn btn-primary" type="submit"><i class="fa fa-floppy-o fa-fw"></i>保 存</button>
                            <button class="btn btn-primary" type="button" onclick="saveMenu();"><i class="fa fa-floppy-o fa-fw"></i>异步保存</button>
                            <button class="btn btn-primary" type="button" onclick="saveBatchMenu();"><i class="fa fa-floppy-o fa-fw"></i>批量提交</button>
                        </div>
                    </div>
                </div>
            </div>
        }
    </div>
</div>
@section FootScript{

    <script type="text/javascript">
        //采用AJAX方式异步提交数据到服务
        function saveMenu() {
            var data = new Object();
            data.Menu_Name = $("#txtMenu_Name").val();
            data.Menu_Code = $("#txtMenu_Code").val();
            data.Menu_URL = $("#txtMenu_URL").val();
            data.Description = $("#txtDescription").val();
            $.post("@Url.Action("CreateAsynchronous")", data, function (result) {
                if (result.Succeed) alert(result.Message);
                if (!reuslt.Succeed) alert(result.Message);

            });
        }

        //采用AJAX方式批量提交数据到服务端
        function saveBatchMenu() {
            var dataList = new Array();
            for (i = 0; i < 10; i++) {
                var menu = new Object();
                menu.Menu_Name = $("#txtMenu_Name").val();
                menu.Menu_Code = $("#txtMenu_Code").val();
                menu.Menu_URL = $("#txtMenu_URL").val();
                menu.Description = $("#txtDescription").val();
                dataList.push(menu);
            }
            $.post("@Url.Action("BatchCreate")", dataList, function (result) {
                if (result.Succeed) alert(result.Message);
                if (!reuslt.Succeed) alert(result.Message);

            });
        }
    </script>
}
